using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class PostMenu : BaseItem
    {
        private PostMenu() : base() { }
        private PostMenu(Hashtable table) : base(table) { }
        private PostMenu(Hashtable table, List<PostMenu> collection) : base(table, collection) { }

   
        protected override Base CreateDal()
        {
            return new PostMenuDal();
        }
        
        public static PostMenu CreateInstance()
        {
            return new PostMenu();
        }

        public static PostMenu CreateInstance(int postId, int menuId, bool included)
        {
            PostMenu tmp = new PostMenu();
            tmp.PostId = postId;
            tmp.MenuId = menuId;
            tmp.Included = included;
            return tmp;
        }

        private static PostMenu Get(Hashtable table)
        {
            if (table == null)
            {
                return null;
            }
            else
            {
                return new PostMenu(table);
            }
        }

        private static List<PostMenu> Get(Hashtable[] tables)
        {
            if (tables == null)
            {
                return null;
            }
            else
            {
                List<PostMenu> tmp = new List<PostMenu>();
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new PostMenu(table, tmp));
                }
                return tmp;
            }
        }

        public static List<PostMenu> GetAllByPostId(int postId)
        {
            PostMenuDal dal = new PostMenuDal();
            return Get(dal.GetAllByPostId(postId));
        }

        public new void Update()
        {
            base.Update();
        }


        protected override object SaveChanges(ref object concurencyId, Base dal)
        {
            ((PostMenuDal)dal).Update(PostId, MenuId, Included, ref concurencyId);
            return string.Concat(MenuId, "_", PostId);
        }

        protected override void Load(Hashtable table)
        {
            PostId = (int)table[PostMenuDal.Fields.PostId];
            MenuId = (int)table[PostMenuDal.Fields.MenuId];
            Included = (bool)table[PostMenuDal.Fields.Included];
        }

        public int PostId { get; private set; }
        public int MenuId { get; private set; }
        public bool Included { get; set; }

 
    }
}
